package com.saltedfish.tool.model;

import com.saltedfish.tool.util.SharePreferceUtils;

/**
 * 
* @ClassName: User 
* @Description: TODO(这里用一句话描述这个类的作用) 
* @author yiw
* @date 2015-12-28 下午3:45:04 
*
 */
public class User {

    public static final String IS_LOGIN = "IS_LOGIN";
    public static final String USER_ID = "USER_ID";
    public static final String USER_REAL_NAME = "USER_REAL_NAME";
    public static final String USER_NAME = "USER_NAME";
    public static final String saltFishNo = "saltFishNo";

    public static final String USER_PHONE = "USER_PHONE";
    public static final String USER_TOKEN = "USER_TOKEN";
    public static final String USER_IMAGE = "Photo";
    public static final String USER_POSITION = "position";

    public static final String USER_CIRCLEFRIENDSPHOTO = "circleFriendsPhoto";

    public static final String USER_Company = "Company";
    public static final String USER_STATUS = "authenticationStatus";
    public static final String SET_HELP = "set_help";
    public static final String USER_SIGN = "user_sign";
    /**
     * 关于快捷打卡需要保存的字段
     */
    public static final String USER_UPCLOCKTYPE  = "user_upClockType";
    public static final String USER_UPEND = "user_upend";
    public static final String USER_UPSTART = "user_upstart";
    public static final String USER_DOWNCLOCKTYPE  = "user_downClockType";
    public static final String USER_DOWNEND = "user_downEnd";
    public static final String USER_DOWNSTART = "user_downStart";


    private static User mUser;
    public UserInfo userInfo;

    private User() {
        userInfo = new UserInfo();
      //  getLocalData();
    }

    public static User getInstance() {
        if (mUser == null) {
            mUser = new User();
        }
        return mUser;
    }

    /**
     * 初始化本地数据
     */
    private void getLocalData() {

        SharePreferceUtils.setString(USER_ID, userInfo.userId);
        SharePreferceUtils.setString(USER_REAL_NAME, userInfo.petName);
        SharePreferceUtils.setString(USER_PHONE, userInfo.phone);
        SharePreferceUtils.setString(USER_NAME, userInfo.userName);
        SharePreferceUtils.setString(saltFishNo, userInfo.saltFishNo);

//        SharePreferceUtils.setString(USER_TOKEN, userInfo.getToken());
        SharePreferceUtils.setString(USER_IMAGE, userInfo.logoUrl);
//        SharePreferceUtils.setString(USER_POSITION, userInfo.getPosition());

//        SharePreferceUtils.setString(USER_CIRCLEFRIENDSPHOTO, userInfo.getCircleFriendsPhoto());

//        SharePreferceUtils.setString(USER_ENDTIME, userInfo.getAuthenticationEndTime());
//        SharePreferceUtils.setString(USER_STATUS, userInfo.getAuthenticationStatus() + "");
//        if (userInfo.getFunctionSwitch() != null) {
//            UserInfo.FunctionSwitch functionSwitch = userInfo.getFunctionSwitch();
//            SharePreferceUtils.setString(SET_HELP, functionSwitch.getHelp());
//        }

        SharePreferceUtils.setString(IS_LOGIN, "0");
//        SharePreferceUtils.setString(USER_SIGN, userInfo.getUserSign());
    }

    /**
     * 保存数据
     */
    private void saveData() {
        SharePreferceUtils.setString(USER_ID, userInfo.userId);
        SharePreferceUtils.setString(USER_REAL_NAME, userInfo.petName);
        SharePreferceUtils.setString(USER_PHONE, userInfo.phone);
        SharePreferceUtils.setString(USER_NAME, userInfo.userName);
        SharePreferceUtils.setString(USER_IMAGE, userInfo.logoUrl);
        SharePreferceUtils.setString(saltFishNo, userInfo.saltFishNo);

//        SharePreferceUtils.setString(USER_CIRCLEFRIENDSPHOTO, userInfo.getCircleFriendsPhoto());
//        SharePreferceUtils.setString(USER_ENDTIME, userInfo.getAuthenticationEndTime());
//        SharePreferceUtils.setString(USER_STATUS, userInfo.getAuthenticationStatus() + "");
//        if (userInfo.getFunctionSwitch() != null) {
//            UserInfo.FunctionSwitch functionSwitch = userInfo.getFunctionSwitch();
//            SharePreferceUtils.setString(SET_HELP, functionSwitch.getHelp());
//        }
        SharePreferceUtils.setString(IS_LOGIN, "1");
//        SharePreferceUtils.setString(USER_SIGN, userInfo.getUserSign());
//
//        SharePreferceUtils.setString(USER_UPCLOCKTYPE, userInfo.getUpClockType());
//        SharePreferceUtils.saveInt(USER_UPEND, userInfo.getUpEnd());
//        SharePreferceUtils.saveInt(USER_UPSTART, userInfo.getUpStart());
//        SharePreferceUtils.setString(USER_DOWNCLOCKTYPE, userInfo.getDownClockType());
//        SharePreferceUtils.saveInt(USER_DOWNEND, userInfo.getDownEnd());
//        SharePreferceUtils.saveInt(USER_DOWNSTART, userInfo.getDownStart());
    }

    /**
     * 登陆成功
     *
     * @param info
     */
    public void loginSuccess(LoginInfo info) {
        userInfo = info.userInfo;
        SharePreferceUtils.setString(USER_TOKEN, info.token);
        saveData();

    }

    public void setUserInfo(UserInfo info) {
        //   info.token = userInfo.token;
        userInfo = info;
        saveData();
    }


    /**
     * 更新数据
     */
    public void updateData(MemberInfo memberInfo) {
        SharePreferceUtils.setString(USER_ID, memberInfo.getMemberId());
        SharePreferceUtils.setString(USER_REAL_NAME, memberInfo.getName());
        SharePreferceUtils.setString(USER_PHONE, memberInfo.getPhone());
        SharePreferceUtils.setString(USER_Company, memberInfo.getCompany());
        SharePreferceUtils.setString(USER_IMAGE, memberInfo.getPhoto());
        SharePreferceUtils.setString(USER_POSITION, memberInfo.getPosition());

    }
    /**
     * 退出登陆
     */
    public void logoutSuccess() {
        SharePreferceUtils.setString(USER_ID, "");
        SharePreferceUtils.setString(USER_REAL_NAME, "");
        SharePreferceUtils.setString(USER_TOKEN, "");
        SharePreferceUtils.setString(IS_LOGIN, "0");
        SharePreferceUtils.setString(USER_NAME, "");
        SharePreferceUtils.setString(USER_IMAGE, "");
        SharePreferceUtils.setString(USER_POSITION, "");
        SharePreferceUtils.setString(USER_CIRCLEFRIENDSPHOTO, "");
        SharePreferceUtils.setString(USER_SIGN, "");
        SharePreferceUtils.setString(saltFishNo, "");

    }


}
